/*

1.USART1串口和PC通信，波特率115200
2.硬件连接：
	mpi6050 VCC  3.3V
					SCL  PB8
					SDA  PB9
					ADO  GND  地址0x68
	USART1	TX	 PA10
					RX	 PA9

*/

# include "I2Cdev.h"
# include "MPU6050.h"
# include "usart.h"
#include "inv_mpu.h"
#include "inv_mpu_dmp_motion_driver.h" 
#include "PWM.h"
#include "led.h"
#include "sys.h"

volatile float pitch,roll,yaw; 		//欧拉角 
volatile  u8 mode; 
 	u8 t=0;			


volatile	short aacx,aacy,aacz;		//加速度传感器原始数据 
volatile short gyrox,gyroy,gyroz;	//陀螺仪原始数据 
	short temp;					//温度	

extern u16 coordinate_buffer[10];  

int main (void)
{
	short flag_mpu, flag_dmp;

	//NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);	 //设置NVIC中断分组2:2位抢占优先级，2位响应优先级
	uart_init(9600);
	delay_init(168);
	LED_Init();		  			//初始化与LED连接的硬件接口
	
	TIM3_PWM_Init(999,8);	  //初始化脉宽波输出	
	TIM2_Int_Init(49,7199);		//初始化定时器2，每5ms产生一次中断

	flag_mpu = MPU_Init();
	flag_dmp = mpu_dmp_init();
	
	while(flag_mpu)
	{
		printf("\r\n mup6050初始化失败 \r\n");
		delay_ms(500);
	}
	while(flag_dmp)
	{
		printf("\r\n DMP初始化失败,出错位置：%d \r\n",flag_dmp);
		delay_ms(500);
	}
	
	while(1)
	{
		if(mpu_dmp_get_data(&pitch,&roll,&yaw)==0)
		{ 
			LED0=!LED0;
		}
	}
}
